using System;
using System.Collections.Generic;
using System.Linq;

using octalforty.Componento.Core.Framework;

namespace octalforty.Componento.Core.ApplicationServices
{
    public class PackageResourceInstallerService
    {
        private readonly IEnumerable<IPackageResourceInstaller> packageResourceInstallers;

        public PackageResourceInstallerService(IEnumerable<IPackageResourceInstaller> packageResourceInstallers)
        {
            this.packageResourceInstallers = packageResourceInstallers;
        }

        public void InstallResource(Uri resourceUri, string targetDirectory)
        {
            var installer = packageResourceInstallers.FirstOrDefault(prp => prp.SupportedSchemas.Contains(resourceUri.Scheme.ToLowerInvariant()));

            if(installer != null)
                installer.InstallResource(resourceUri, targetDirectory);
        }
    }
}